import cv2

img = cv2.imread('img/example.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

ret, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
print(ret) # 99
cv2.imshow('', thresh)
cv2.waitKey(0)